package tt.dz.egobus.servicemanager.vo;

import org.hibernate.validator.constraints.NotBlank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.api.commoncenter.bean.ConfigBack;

import java.io.Serializable;
import java.util.List;

/**
 * @author Anson
 * @date 17-8-11
 * @name
 * @since 1.0.6
 */
public class RuntimeConfigViewVo implements Serializable {
    private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeConfigViewVo.class);
    private static final long serialVersionUID = -8068252584602137810L;


    public ConfigBack convert() {
        ConfigBack pojo = new ConfigBack();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("RuntimeConfigViewVo -> ConfigBack bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;
    }

    public RuntimeConfigViewVo view(ConfigBack pojo) {
        try {
            BeanUtils.copyProperties(pojo, this);
        } catch (BeansException e) {
            LOGGER.error(" ConfigBack ->  RuntimeConfigViewVo bean拷贝异常, viewVo={}", this, e);
        }
        return this;
    }

    /**
     * 配置项的名称
     **/
    @NotBlank(message = "配置项的名称不能为空")
    private String name;

    /**
     * 配置项的惟一标识
     **/
    @NotBlank(message = "配置项的惟一标识不能为空")
    private String key;

    /**
     * 配置项的默认值
     **/
    @NotBlank(message = "配置项的默认值不能为空")
    private String defaultValue;

    /**
     * 配置项的值
     **/
    private String value;

    /**
     * 配置项的类型
     **/
    private String type;

    /**
     * 配置项的说明
     **/
    private String desc;

    /**
     * 配置项是否有效
     **/
    private Boolean isValidate;

    /**
     * element的类型
     **/
    private String elementType;

    /**
     * 可选值
     **/
    private List<String> strings;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Boolean getValidate() {
        return isValidate;
    }

    public void setValidate(Boolean validate) {
        isValidate = validate;
    }

    public String getElementType() {
        return elementType;
    }

    public void setElementType(String elementType) {
        this.elementType = elementType;
    }

    public List<String> getStrings() {
        return strings;
    }

    public void setStrings(List<String> strings) {
        this.strings = strings;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        RuntimeConfigViewVo that = (RuntimeConfigViewVo) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (key != null ? !key.equals(that.key) : that.key != null) return false;
        if (defaultValue != null ? !defaultValue.equals(that.defaultValue) : that.defaultValue != null) return false;
        if (value != null ? !value.equals(that.value) : that.value != null) return false;
        if (type != null ? !type.equals(that.type) : that.type != null) return false;
        if (desc != null ? !desc.equals(that.desc) : that.desc != null) return false;
        if (isValidate != null ? !isValidate.equals(that.isValidate) : that.isValidate != null) return false;
        if (elementType != null ? !elementType.equals(that.elementType) : that.elementType != null) return false;
        return strings != null ? strings.equals(that.strings) : that.strings == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (key != null ? key.hashCode() : 0);
        result = 31 * result + (defaultValue != null ? defaultValue.hashCode() : 0);
        result = 31 * result + (value != null ? value.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (desc != null ? desc.hashCode() : 0);
        result = 31 * result + (isValidate != null ? isValidate.hashCode() : 0);
        result = 31 * result + (elementType != null ? elementType.hashCode() : 0);
        result = 31 * result + (strings != null ? strings.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "ConfigBack{" +
                "name='" + name + '\'' +
                ", key='" + key + '\'' +
                ", defaultValue='" + defaultValue + '\'' +
                ", value='" + value + '\'' +
                ", type='" + type + '\'' +
                ", desc='" + desc + '\'' +
                ", isValidate=" + isValidate +
                ", elementType='" + elementType + '\'' +
                ", strings=" + strings +
                '}';
    }
}
